import InfoPage, {InfoPageType} from "../code/common/InfoPage";
import * as React from "../../script/frame/apiModel/gui/React";
import {GuiId, GuiKeys} from "../../script/controller/model/ControllerOpt";
import DialogPage from "../code/common/DialogPage";
import {ComponentTree, UISyncData} from "../../script/frame/apiModel/gui/React";
import {ResourceKey} from "../../script/constant/ResourceConstant";


export class PublicGui {
    infoPage: InfoPage
    infoPage2: InfoPage
    dialogPage: DialogPage

    init () {
        this.infoPage = <InfoPage key={GuiKeys.infoPageCon}></InfoPage>
        React.render(this.infoPage, ComponentTree.getInstance().root)

        this.infoPage2 = <InfoPage key={GuiKeys.infoPageCon2}></InfoPage>
        React.render(this.infoPage2, ComponentTree.getInstance().root)

        this.dialogPage = <DialogPage key={GuiKeys.dialogPageCon}></DialogPage>
        React.render(this.dialogPage, ComponentTree.getInstance().root)
    }

    showInfoPage (x: number, y: number,title: string, subtitle?: string, des?: string, pageType?: InfoPageType) {
        this.infoPage.setState({
            ...this.infoPage.state,
            x: x,
            y: y,
            title: title,
            subtitle: subtitle,
            des: des,
            pageType: pageType,
            visible: true,
        })
    }
    closeInfoPage () {
        this.infoPage.setState({
            ...this.infoPage.state,
            visible: false,
        })
    }
    showInfoPage2 (x: number, y: number,title: string, subtitle?: string, des?: string, pageType?: InfoPageType) {
        this.infoPage2.setState({
            ...this.infoPage2.state,
            x: x,
            y: y,
            title: title,
            subtitle: subtitle,
            des: des,
            pageType: pageType,
            visible: true,
        })
    }
    closeInfoPage2 () {
        this.infoPage2.setState({
            ...this.infoPage2.state,
            visible: false,
        })
    }
    showDialogPage (w: number, title: string, des?: string, back?: ResourceKey, okButton?: ResourceKey, cancelButton?: ResourceKey, okFun?: () => UISyncData, cancelFun?: () => UISyncData, buttonSize?: { w: number, h: number }) {
        this.dialogPage.setState({
            ...this.dialogPage.state,
            w: w,
            title: title,
            des: des,
            okButton: okButton,
            cancelButton: cancelButton,
            okFun: okFun,
            cancelFun: cancelFun,
            buttonSize,
            back: back,
            visible: true,
        })
    }
    closeDialogPage () {
        this.dialogPage.setState({
            ...this.dialogPage.state,
            visible: false,
        })
    }
}

export const publicGui = new PublicGui();